<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="ligerForm">
				<div class="fieldset1 tabel_col clearFix">
					<div class="caption">
						<span class="title">基本信息</span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">交接单名称</div>
						<div class="field">
							<input id="listName"  name="listName"  type="text"  title="${entity.listName}"
								value="${entity.listName}"  />
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">版本号</div>
						<div class="field">${entity.version}
						</div>
					</div>
					<div class="caption">
						<span class="title">筛选条件</span>
					</div>
					
					<div class="fieldBox col_100">
						<div class="label">承租人类型 </div>
						<div class="field">
						<c:if test="${operate != 'view'}">（<input type="checkbox" onchange="selectAll(this,'lesseeType');"/>全选）</c:if>
							<c:forEach items="${lesseeTypeList}" var="item">
								<input  class="conditionClass"   name="lesseeType"    type="checkbox"  <c:if test="${item.isHide}">checked="checked"</c:if>  value="${item.key}">${item.value}  
							</c:forEach>
						</div>
					</div>
					<div class="fieldBox col_100">
						<div class="label">合同签署方式</div>
						<div class="field">
						<c:if test="${operate != 'view'}">（<input type="checkbox" onchange="selectAll(this,'contractSign');"/>全选）</c:if>
							<c:forEach items="${contractSignList}" var="item">
								<input  class="conditionClass"  name="contractSign"   type="checkbox"  <c:if test="${item.isHide}">checked="checked"</c:if> value="${item.key}">${item.value}  
							</c:forEach>
						</div>
					</div>
					<div class="fieldBox col_100">
						<div class="label">事业部</div>
						<div class="field">
						<c:if test="${operate != 'view'}">（<input type="checkbox" onchange="selectAll(this,'buOrgCd');"/>全选）</c:if>
							<c:forEach items="${buOrgCdList}" var="item">
								<input  class="conditionClass"  name="buOrgCd"   type="checkbox"  <c:if test="${item.isHide}">checked="checked"</c:if> value="${item.key}">${item.value}  
							</c:forEach>
						</div>
					</div>
					<div class="fieldBox col_100">
						<div class="label">业务类型</div>
						<div class="field">
						<c:if test="${operate != 'view'}">（<input type="checkbox" onchange="selectAll(this,'prjBizType');"/>全选）</c:if>
							<c:forEach items="${prjBizTypeList}" var="item">
								<input  class="conditionClass"  name="prjBizType"   type="checkbox"  <c:if test="${item.isHide}">checked="checked"</c:if> value="${item.key}">${item.value}  
							</c:forEach>
						</div>
					</div>
					<div class="fieldBox col_100">
						<div class="label">担保人</div>
						<div class="field">
						<c:if test="${operate != 'view'}">（<input type="checkbox" onchange="selectAll(this,'guarantee');"/>全选）</c:if>
							<c:forEach items="${guaranteeList}" var="item">
								<input  class="conditionClass"  name="guarantee"   type="checkbox"  <c:if test="${item.isHide}">checked="checked"</c:if>  value="${item.key}">${item.value}  
							</c:forEach>
						</div>
					</div>
					<div class="fieldBox col_100">
						<div class="label">担保人类型</div>
						<div class="field">
						<c:if test="${operate != 'view'}">（<input type="checkbox" onchange="selectAll(this,'guaranteeType');"/>全选）</c:if>
							<c:forEach items="${guaranteeTypeList}" var="item">
								<input  class="conditionClass"  name="guaranteeType"   type="checkbox"  <c:if test="${item.isHide}">checked="checked"</c:if> value="${item.key}">${item.value}  
							</c:forEach>
						</div>
					</div>
					<div class="fieldBox col_100">
						<div class="label">担保签署方式</div>
						<div class="field">
						<c:if test="${operate != 'view'}">（<input type="checkbox" onchange="selectAll(this,'guaranteeSign');"/>全选）</c:if>
							<c:forEach items="${guaranteeSignList}" var="item">
								<input  class="conditionClass"  name="guaranteeSign"   type="checkbox"  <c:if test="${item.isHide}">checked="checked"</c:if> value="${item.key}">${item.value}  
							</c:forEach>
						</div>
					</div>
					<div class="fieldBox col_100">
						<div class="label">结清类型</div>
						<div class="field">
						<c:if test="${operate != 'view'}">（<input type="checkbox" onchange="selectAll(this,'settleType');"/>全选）</c:if>
							<c:forEach items="${settleTypeList}" var="item">
								<input class="conditionClass" name="settleType"   type="checkbox"  <c:if test="${item.isHide}">checked="checked"</c:if> value="${item.key}">${item.value}  
							</c:forEach>
						</div>
					</div>
					<div class="fieldBox col_100">
						<div class="label">项目类型</div>
						<div class="field">
						<c:if test="${operate != 'view'}">（<input type="checkbox" onchange="selectAll(this,'projectType');"/>全选）</c:if>
							<c:forEach items="${projectTypeList}" var="item">
								<input class="conditionClass" name="projectType"   type="checkbox"  <c:if test="${item.isHide}">checked="checked"</c:if> value="${item.key}">${item.value}  
							</c:forEach>
						</div>
					</div>
					<div class="fieldBox col_100">
						<div class="label">融资机构</div>
						<div class="field">
						<c:if test="${operate != 'view'}">（<input type="checkbox" onchange="selectAll(this,'fundCompany');"/>全选）</c:if>
							<c:forEach items="${friBaseInfoDTOList}" var="item">
								<input class="conditionClass" name="fundCompany"   type="checkbox"   <c:if test="${item.rem=='checked'}">checked="checked"</c:if> value="${item.id}">${item.fundRasInsNm}  
							</c:forEach>
						</div>
					</div>
					<div class="fieldBox col_100">
						<div class="label">资管业务</div>
						<div class="field">
						<c:if test="${operate != 'view'}">（<input type="checkbox" onchange="selectAll(this,'assetManage');"/>全选）</c:if>
							<c:forEach items="${assetManageList}" var="item">
								<input  class="conditionClass"  name="assetManage"   type="checkbox"  <c:if test="${item.isHide}">checked="checked"</c:if>  value="${item.key}">${item.value}  
							</c:forEach>
						</div>
					</div>
					
					
					
					<div class="caption">
						<span class="title">资料清单</span>
							<c:if test="${operate != 'view'}">
								<div style="margin-left: auto;margin-right: 10px;width:200px;margin-top: -15px">
									<span id="scm_cost2_sv_btn_id"
										class="sq-button sq-button-round" onclick="addReceiptDetail();">新增
									</span>
									<span id="scm_cost2_del_btn_id"
										class="sq-button sq-button-round" onclick="delRow();" >删除选中行
									</span>
								</div>
						</c:if>
					</div>
					
					<div class="fieldBox col_100">
						<div style="width: 98%; margin-left: 1%;">
							<div id="ligergrid1" class="sq-grid"></div>
						</div>
					</div>
					
				</div>
				
				<div class="btnsBox">
					<c:if test="${operate != 'view'}">
						<span id="saveBtn" class="sq-button sq-button-round" onclick="save();">保存</span>
						<!-- <span id="closeBtn" class="sq-button sq-button-round" onclick="Remove_navTab();">关闭</span> -->
					</c:if>
				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript">
		var grid;
		var feeTypCdListJSON = [];
	     feeTypCdListJSON = [{"code":"02","codeNm":"客户保证金","isSysDef":0,"isSysDefNm":"否"},{"code":"05","codeNm":"咨询费2","isSysDef":0,"isSysDefNm":"否"},{"code":"08","codeNm":"供应商返利","isSysDef":0,"isSysDefNm":"否"},{"code":"37","codeNm":"GPS返利","isSysDef":0,"isSysDefNm":"否"},{"code":"09","codeNm":"利率上浮","isSysDef":0,"isSysDefNm":"否"},{"code":"10","codeNm":"GPS","isSysDef":0,"isSysDefNm":"否"},{"code":"11","codeNm":"保险保证金","isSysDef":0,"isSysDefNm":"否"},{"code":"12","codeNm":"补偿款保证金","isSysDef":0,"isSysDefNm":"否"},{"code":"13","codeNm":"厂商保证金","isSysDef":0,"isSysDefNm":"否"},{"code":"14","codeNm":"车辆滞纳金","isSysDef":0,"isSysDefNm":"否"},{"code":"15","codeNm":"担保费","isSysDef":0,"isSysDefNm":"否"},{"code":"16","codeNm":"第1年管理费","isSysDef":0,"isSysDefNm":"否"},{"code":"17","codeNm":"第2年管理费","isSysDef":0,"isSysDefNm":"否"},{"code":"18","codeNm":"调查费","isSysDef":0,"isSysDefNm":"否"},{"code":"19","codeNm":"公证抵押费","isSysDef":0,"isSysDefNm":"否"},{"code":"20","codeNm":"机动车车辆保险","isSysDef":0,"isSysDefNm":"否"},{"code":"21","codeNm":"建档费","isSysDef":0,"isSysDefNm":"否"},{"code":"22","codeNm":"经销商保证金","isSysDef":0,"isSysDefNm":"否"},{"code":"23","codeNm":"其他收入","isSysDef":0,"isSysDefNm":"否"},{"code":"24","codeNm":"上牌抵押费","isSysDef":0,"isSysDefNm":"否"},{"code":"25","codeNm":"授信额","isSysDef":0,"isSysDefNm":"否"},{"code":"26","codeNm":"缩（展）期费用","isSysDef":0,"isSysDefNm":"否"},{"code":"27","codeNm":"机动车交通事故责任强制保险","isSysDef":0,"isSysDefNm":"否"},{"code":"28","codeNm":"残值","isSysDef":0,"isSysDefNm":"否"},{"code":"29","codeNm":"贴息","isSysDef":0,"isSysDefNm":"否"},{"code":"30","codeNm":"购置税","isSysDef":0,"isSysDefNm":"否"},{"code":"31","codeNm":"车船税","isSysDef":0,"isSysDefNm":"否"},{"code":"32","codeNm":"保险总额","isSysDef":0,"isSysDefNm":"否"},{"code":"33","codeNm":"风险保证金","isSysDef":0,"isSysDefNm":"否"},{"code":"34","codeNm":"风险保证金1","isSysDef":0,"isSysDefNm":"否"},{"code":"35","codeNm":"保养","isSysDef":0,"isSysDefNm":"否"},{"code":"36","codeNm":"装具","isSysDef":0,"isSysDefNm":"否"},{"code":"38","codeNm":"五路一桥费用","isSysDef":0,"isSysDefNm":"否"},{"code":"39","codeNm":"保险增项费","isSysDef":0,"isSysDefNm":"否"},{"code":"40","codeNm":"充电桩金额","isSysDef":0,"isSysDefNm":"否"},{"code":"41","codeNm":"上牌费用","isSysDef":0,"isSysDefNm":"否"},{"code":"42","codeNm":"改装费用","isSysDef":0,"isSysDefNm":"否"},{"code":"43","codeNm":"运输费用","isSysDef":0,"isSysDefNm":"否"},{"code":"44","codeNm":"销售费用","isSysDef":0,"isSysDefNm":"否"},{"code":"45","codeNm":"年检费","isSysDef":0,"isSysDefNm":"否"},{"code":"46","codeNm":"维修费","isSysDef":0,"isSysDefNm":"否"},{"code":"47","codeNm":"每月返利","isSysDef":0,"isSysDefNm":"否"},{"code":"48","codeNm":"借款费用","isSysDef":0,"isSysDefNm":"否"},{"code":"49","codeNm":"销售返利","isSysDef":0,"isSysDefNm":"否"}]; 
	     <c:if test="${not empty feeTypCdListJSON}"> feeTypCdListJSON = ${feeTypCdListJSON}; </c:if>
	     
		$(function() {
			$("#ligerForm").ligerForm({
				validate: true
			});
			initGrid();//初始化交接单明细

			<c:if test="${operate == 'view'}"> 
				//如果是查看页面，设置不可用
				$(".conditionClass").attr('disabled',true);
				$("#listName").attr('disabled',true);
			</c:if>
			<c:if test="${operate == 'update'}"> 
				$("#listName").attr('disabled',true);
			</c:if>
	    });
		
		//初始化交接单明细
		function initGrid(){
			//是否
			var yesOrNoCdListJSON = [{"isHide":false,"key":"1","value":"是"},{"isHide":false,"key":"0","value":"否"}]; 
			//归档地点
			var arcPlaceJSON = [{"key":"1","value":"总部"},{"key":"2","value":"省公司"}]; 
		     
			$("#ligergrid1").ligerGrid({
				url:'<%=path%>/archive/arcReceiptMain/arcReceiptDetailList.do?arcReceiptMainId=${entity.id}',
				method:'get',
				//parms:getSearchParams(),
				columns:[
					{ display: '档案基础信息ID', name: 'arcBscInfo',type:'text',hide:true},
					{ display: '权证类别', name: 'warrantTypeNm',type:'text'},
					{ display: '权证名称', name: 'warrantName',type:'text'},
					{display:'资料类型', name: 'type', 
						editor: { type: 'select', valueField: 'key', textField: 'value',
							data: [
			                    { value: '原件', key: '1' },
			                    { value: '复印件', key: '2' },
			                    { value: '电子件', key: '3' }
			                ]
						},render: function (item)
			               {
			                   if (parseInt(item.type) == 1) return '原件';
			                   if (parseInt(item.type) == 2) return '复印件';
			                   if (parseInt(item.type) == 3) return '电子件';
			               }
		           },{display:'是否必选', name: 'ischoice',
		        	   editor: { type: 'select', valueField: 'key', textField: 'value',
							data: [
			                    { value: '是', key: '1' },
			                    { value: '否', key: '0' }
			                ]
						},render: function (item)
			               {
			                   if (parseInt(item.ischoice) == 1) return '是';
			                   if (parseInt(item.ischoice) == 0) return '否';
			               }
					},{display:'扫描件', name: 'isScanRequire',
			        	   editor: { type: 'select', valueField: 'key', textField: 'value',
								data: [
				                    { key: '1', value: '必填'  },
				                    { key: '0', value: '非必填' }
				                ]
							},render: function (item)
				               {
				                   if (parseInt(item.isScanRequire) == 1) return '必填';
				                   if (parseInt(item.isScanRequire) == 0) return '非必填';
				               }
						},{display:'操作人', name: 'upUserCd',
				        	   editor: { type: 'select', valueField: 'key', textField: 'value',
									data: [
					                    { key: '1', value: '合同管理员'  },
					                    { key: '2', value: '信审' }
					                ]
								},render: function (item)
					               {
					                   if (parseInt(item.upUserCd) == 1) return '合同管理员';
					                   if (parseInt(item.upUserCd) == 2) return '信审';
					               }
							},{display:'归档地点', name: 'arcPlace',
							 editor: {
				                    type: 'select',
				                    data: arcPlaceJSON,
				                    valueField: 'key',
				                    textField: 'value'
				                },
				                valueField: 'arcPlace',
				                textField: 'arcPlaceNm',
				                render: function (item) {
				                    return item.arcPlaceNm;
				                }
						}/*,{display: '费用类型', name: 'feeTypCd', minWidth: 80,
			                editor: {
			                    type: 'select',
			                    data: feeTypCdListJSON,
			                    valueField: 'code',
			                    textField: 'codeNm'
			                },
			                valueField: 'feeTypCd',
			                textField: 'feeTypCdNm',
			                render: function (item) {
			                    //return item.feeTypCdNm;
			                    return "供应商返利";
			                }
			            }*/,{display:'份数',name: 'fenshu',type:'int',editor: { type: 'int' }}
				],onBeforeSubmitEdit: f_onBeforeSubmitEdit0,
		        <c:if test="${operate != 'view'}">
			        enabledEdit: true,
				</c:if>
				usePager: false,//是否有分页便签
				isScroll: true,//是否有滚动条
				//pageSize:10,
				root:'rows',
				record:'total',
				hideLoadButton:false,
				width:'100%',
				height:'500',
				heightDiff:-2,
				checkbox:true,//列表是否有选择框
				rownumbers:true,//列表是否有行号
				selectRowButtonOnly:true,//复选框模式时，是否只允许点击复选框才能选择行
				//选择行事件
				onSelectRow: function(rowdata, rowid, rowobj){
					
				},
				//取消选择行事件
				onUnSelectRow : function(rowdata, rowid, rowobj){
					
				}
			});
			grid = liger.get("ligergrid1");
			//grid.setHeight(10);
			//grid.options.isSingleCheck = true;//列表是否为单选
		}
		
		//限制录入金额
	    function f_onBeforeSubmitEdit0(e)
	    { 
	        if (e.column.name == "fenshu")
	        {
	    		if(e.value != "" && e.value <=0){
	            	alert('份数必须大于0');
	    			return false;
	    		}
	        }
	       
	        return true;
	    }
		
		//保存
		function save(){
			var ligerForm = liger.get("ligerForm");
			if (!ligerForm.valid()) {
				$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
				return false; 
			}
			
			
			if($.trim($("#listName").val()) == ""){
				$.ligerDialog.SQalert({content: "请填写交接单名称",SQ_type: "warning"});
				return false;
			}
			
		/* 	//验证筛选条件
			console.log( liger.get("lesseeType").getValue());
			console.log($("#lesseeType").val());
			return ; */
			
			
			var data = ligerForm.getData();//主表数据
			var gridData = grid.getData();
			if(gridData.length == 0) {
				$.ligerDialog.SQalert({content: "请先选择资料清单",SQ_type: "warning"});
				return ;
			}
			
			//验证资料清单，是否已选择
			for(var i=0;i<gridData.length;i++) {
				if(!gridData[i].type) {
					$.ligerDialog.SQalert({content: "第"+(i+1)+"行，请选择 '资料类型'",SQ_type: "warning"});
					return ;
				}
				if(!gridData[i].ischoice) {
					$.ligerDialog.SQalert({content: "第"+(i+1)+"行，请选择 '是否必选'",SQ_type: "warning"});
					return ;
				}
				if(!gridData[i].isScanRequire) {
					$.ligerDialog.SQalert({content: "第"+(i+1)+"行，请选择 '扫描件'",SQ_type: "warning"});
					return ;
				}
				if(!gridData[i].arcPlace) {
					$.ligerDialog.SQalert({content: "第"+(i+1)+"行，请选择 '归档地点'",SQ_type: "warning"});
					return ;
				}
				if(gridData[i].ischoice == 1) {
					if(!gridData[i].fenshu) {
						$.ligerDialog.SQalert({content: "第"+(i+1)+"行，请填写 '份数'",SQ_type: "warning"});
						return ;
					}
				}
			}
			
			data["json"] = JSON.stringify(gridData);//明细数据
			//alert(JSON.stringify(data));
			//alert(JSON.stringify(grid.getData()));
			//alert(JSON.stringify($("#ligerForm").serialize()));
			//console.log((JSON.stringify(data)));
			
			var wait_dialog = null;
			var id="${entity.id}";
			$.ajax({
				type: 'post',
				dataType: 'json',
				data: data,
				url: '<%=path%>/archive/arcReceiptMain/save.do?id='+id,
				beforeSend: function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
				},success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
							//$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
							alert(msg.info);
							//if(id == "") {
								Remove_navTab();//新增/修改后，关闭当前页面
							//}
					}else{
						$.ligerDialog.SQalert({content: msg.info,SQ_type: "error",SQ_showButtons: true});
					}
				},error:function (XMLHttpRequest, textStatus, errorThrown) { 
					wait_dialog.close();
					$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
				} 
			});
		}
		//删除已选行
		function delRow(){ 
			grid.deleteSelectedRow();
        } 
		
		//新增交接单明细
		function addReceiptDetail() {
			var addReceiptDetailDialog = 
				$.ligerDialog.SQopen({
			            cls: 'noBorder_Dialog',
			            width: 1000,
			            height:600,
			            title : '选择基础档案资料',
			            url:'<%=path%>/archive/arcBscInfo/arcBscInfoSelect.do?id=',
			             buttons: [{
			            	 text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
				                onclick: function (item, Dialog) {
				                    //在子页面里绑定 frameElement.dialog.onOK = function () {}
				                    if (Dialog.onOk) Dialog.onOk();
				                }
				            }
				        ] ,
			            onClose: function () {
			            	var data = addReceiptDetailDialog._DATA;
			            	if(!data) return;
			                	//交接单页面新增明细
			            	console.log(data);
			            	console.log(grid.getData());
			            	var selectedAllRows = grid.getData();
			        		for (var i=0; i< data.length; i++){ 
			            		//追加行
			            		var canInsert = true;
			            		for (var j=0; j< selectedAllRows.length; j++){ 
			            			if(selectedAllRows[j].arcBscInfo == data[i].id) {
			            				canInsert = false;
			            				break;
			            			}
			            		}
			            		if(canInsert) {
				            		grid.addRow({arcBscInfo: data[i].id,warrantTypeNm: data[i].warrantType, warrantName: data[i].warrantName, ligerIndex: 1});
			            		}
			        		}
			        		
			            }
			        });
		}
		
		function selectAll(thisObj,targetCheckbox) {
			if(thisObj.checked) {//全选
				/* var manager = $("input[name='"+targetCheckbox+"']").ligerCheckBox();
				manager.setValue(true); */
				//liger.get("input[name='"+targetCheckbox+"']").setValue(true)
				$("input[name='"+targetCheckbox+"']").attr('checked',true);
				$("input[name='"+targetCheckbox+"']").siblings('a').addClass("l-checkbox-checked");

			}else {//全部取消
				$("input[name='"+targetCheckbox+"']").attr('checked',false);
				$("input[name='"+targetCheckbox+"']").siblings('a').removeClass("l-checkbox-checked");
			}
			
		}
	</script>
</body>
</html>